package com.pub.dbtools;

/**
 * Title:  一个虚拟数据表管理器的 Javabean
 *
 */

import java.util.ArrayList;
import java.util.Hashtable;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class VisuTable extends HttpServlet {

	// 起始设定两个数据集合属性
	private static VisuTable vecpool; // 唯一性实例
	private int p_pageshownum = 20; // 默认的每页显示记录数

	private DataSimpDto my_priv;
	private DataSimpDto my_filt;

	private Hashtable my_prih = new Hashtable();
	private Hashtable my_psec = new Hashtable();

	private String s_vecname = ""; // 结果集名称
	private String s_hmpfirt = ""; // Hashtable名称
	private String s_hmpsecd = ""; // Hashtable名称
	private String s_totreco = ""; // 结果集总记录数

	private String s_totpage = ""; // 结果集总页数
	private String s_totfiel = ""; // 结果集总字段数

	private String s_nowreco = ""; // 结果集当前记录值
	private String s_reconum = ""; // 当前记录值的偏移量
	private String s_pagsize = ""; // 结果集每页记录数
	private String s_nowpage = ""; // 当前的页数
	private String s_pagefir = ""; // 当前的页数的起始偏移量
	private String s_pageend = ""; // 当前的页数的截止偏移量
	private String s_pagefrc = ""; // 当前的页数的起始记录值
	private String s_pageerc = ""; // 当前的页数的截止记录值
	private String s_addreco = ""; // 当前合计添加的记录数

	private String s_filtkey = ""; // 当前的数据过滤字段
	private String s_filtval = ""; // 当前的数据过滤值
	private String s_vecfilt = ""; // 当前过滤值对应的顺序号

	// 初始化变量/集合
	private HttpSession my_session = null;

	private VisuTable() {
	}

	private void initsession(String dbname) {
		s_vecname = dbname + "L_ABC0-E"; // 结果集名称
		s_hmpfirt = dbname + "L_ABCD-E"; // Hashtable名称
		s_hmpsecd = dbname + "L_ABC1-E"; // Hashtable名称
		s_totreco = dbname + "L_ABC2-E"; // 结果集总记录数

		s_totpage = dbname + "L_ABC3-E"; // 结果集总页数
		s_totfiel = dbname + "L_ABC4-E"; // 结果集总字段数

		s_nowreco = dbname + "L_ABC5-E"; // 结果集当前记录值
		s_reconum = dbname + "L_ABC6-E"; // 当前记录值的偏移量
		s_pagsize = dbname + "L_ABC7-E"; // 结果集每页记录数
		s_nowpage = dbname + "L_ABC8-E"; // 当前的页数
		s_pagefir = dbname + "L_ABC9-E"; // 当前的页数的起始偏移量
		s_pageend = dbname + "L_ABC10-E"; // 当前的页数的截止偏移量
		s_pagefrc = dbname + "L_ABC11-E"; // 当前的页数的起始记录值
		s_pageerc = dbname + "L_ABC12-E"; // 当前的页数的截止记录值
		s_filtkey = dbname + "L_ABC13-E"; // 当前的数据过滤字段
		s_filtval = dbname + "L_ABC14-E"; // 当前的数据过滤值
		s_vecfilt = dbname + "L_ABC15-E"; // 当前过滤值对应的顺序号
		s_addreco = dbname + "L_ABC16-E"; // 当前合计添加的记录数
	}

	private void convertVec() {

		int tt = my_priv.getTotRecord(); // 总记录数
		for (int j = 0; j < tt; j++) {
			String sz1 = my_priv.getDataValue(0, j); // 主键值
			my_prih.put(String.valueOf(j), " " + sz1);
			my_psec.put(sz1, " " + String.valueOf(j));
		}
	}

	private void initvalue(String dbname, HttpServletRequest request) {

		my_session = request.getSession(true);
		initsession(dbname);

		// 当前的数据过滤字段
		my_session.setAttribute(s_filtkey, "");
		// 当前的数据过滤值
		my_session.setAttribute(s_filtval, "");
		// 当前过滤值对应的顺序号
		my_session.setAttribute(s_vecfilt, new ArrayList());

		int tt = my_priv.getTotRecord(); // 总记录数
		int ss = my_priv.getTotField(); // 总字段数

		// 置结果集总字段数
		my_session.setAttribute(s_totfiel, new Integer(ss));
		// 置结果集总记录数
		my_session.setAttribute(s_totreco, new Integer(tt));
		// 置结果集默认每页记录数
		my_session.setAttribute(s_pagsize, new Integer(p_pageshownum));
		// 置结果集当前的记录号
		// if (tt >= 1) {
		my_session.setAttribute(s_nowreco, new Integer(0));
		// } else {
		// my_session.setAttribute(s_nowreco, new Integer(0));
		// }

		// 置结果集当前记录值的偏移量
		// if (tt >= 1)
		// my_session.setAttribute(s_reconum, new Integer(ss + 3));
		// else
		my_session.setAttribute(s_reconum, new Integer(0));

		// 置结果集当前页数
		// if (tt >= 1)
		my_session.setAttribute(s_nowpage, new Integer(1));
		// else
		// my_session.setAttribute(s_nowpage, new Integer(0));

		// 置结果集当前页数的起始记录值
		// if (tt >= 1)
		// my_session.setAttribute(s_pagefrc, new Integer(1));
		// else
		my_session.setAttribute(s_pagefrc, new Integer(0));

		// 置结果集当前页数的截止记录值
		if (tt <= p_pageshownum) {
			my_session.setAttribute(s_pageerc, new Integer(tt));
		} else {
			my_session.setAttribute(s_pageerc, new Integer(p_pageshownum));
		}

		// 置结果集结果集总页数
		if (tt >= 1)
			my_session.setAttribute(s_totpage,
					new Integer(getSumPage(my_priv, p_pageshownum)));
		else
			my_session.setAttribute(s_totpage, new Integer(0));

		// 置结果集当前页数的起始偏移量
		// if (tt >= 1)
		// my_session.setAttribute(s_pagefir, new Integer(ss + 3));
		// else
		my_session.setAttribute(s_pagefir, new Integer(0));

		// 置结果集当前页数的截止偏移量
		if (tt <= p_pageshownum) {
			if (tt < 1)
				my_session.setAttribute(s_pageend, new Integer(0));
			else
				my_session.setAttribute(s_pageend,
						new Integer(ss + 3 + ss * tt));
		} else {
			my_session.setAttribute(s_pageend, new Integer(ss + 3 + ss
					* p_pageshownum));
		}
	}

	private void initvalue(String dbname, HttpServletRequest request, int bj) {
		if (bj < 1) {
			initvalue(dbname, request);
			return;
		}
		my_session = request.getSession(true);
		initsession(dbname);

		int tt = my_priv.getTotRecord(); // 总记录数
		int ss = my_priv.getTotField(); // 总字段数

		// 置结果集总字段数
		my_session.setAttribute(s_totfiel, new Integer(ss));

		// 置结果集总记录数
		my_session.setAttribute(s_totreco, new Integer(tt));

		// 置结果集默认每页记录数
		my_session.setAttribute(s_pagsize, new Integer(p_pageshownum));

		// 置结果集当前的记录号
		// if (tt >= 1) {
		// if (my_session.getAttribute(s_nowreco).toString().trim().equals("0"))
		// {
		// my_session.setAttribute(s_nowreco, new Integer(1));
		// }
		// } else {
		my_session.setAttribute(s_nowreco, new Integer(0));
		// }

		// 置结果集当前记录值的偏移量
		// if (tt >= 1) {
		// if (my_session.getAttribute(s_reconum).toString().trim().equals("0"))
		// {
		// my_session.setAttribute(s_reconum, new Integer(ss + 3));
		// }
		// } else {
		my_session.setAttribute(s_reconum, new Integer(0));
		// }

		// 置结果集当前页数
		if (tt >= 1) {
			if (my_session.getAttribute(s_nowpage).toString().trim()
					.equals("0")) {
				my_session.setAttribute(s_nowpage, new Integer(1));
			}
		} else
			my_session.setAttribute(s_nowpage, new Integer(0));

		// 置结果集当前页数的起始记录值
		if (tt >= 1) {
			if (my_session.getAttribute(s_pagefrc).toString().trim()
					.equals("0")) {
				my_session.setAttribute(s_pagefrc, new Integer(1));
			}
		} else
			my_session.setAttribute(s_pagefrc, new Integer(0));

		// 置结果集当前页数的截止记录值
		if (tt <= p_pageshownum) {
			my_session.setAttribute(s_pageerc, new Integer(tt));
		} else {
			my_session.setAttribute(s_pageerc, new Integer(p_pageshownum));
		}

		// 置结果集结果集总页数
		if (tt >= 1)
			my_session.setAttribute(s_totpage,
					new Integer(getSumPage(my_priv, p_pageshownum)));
		else
			my_session.setAttribute(s_totpage, new Integer(0));

		// 置结果集当前页数的起始偏移量
		if (tt >= 1) {
			String s_nowfrec = my_session.getAttribute(s_pagefrc).toString()
					.trim();
			int i_nowfrec = Integer.parseInt(s_nowfrec);
			my_session.setAttribute(s_pagefir, new Integer(ss * i_nowfrec + 3));
		} else
			my_session.setAttribute(s_pagefir, new Integer(0));

		// 置结果集当前页数的截止偏移量
		if (tt <= p_pageshownum) {
			if (tt < 1)
				my_session.setAttribute(s_pageend, new Integer(0));
			else {
				String s_nowfrec = my_session.getAttribute(s_pageerc)
						.toString().trim();
				int i_nowfrec = Integer.parseInt(s_nowfrec);
				my_session.setAttribute(s_pagefir, new Integer(ss * i_nowfrec
						+ 3));
			}
		} else {
			my_session.setAttribute(s_pageend, new Integer(ss + 3 + ss
					* p_pageshownum));
		}
	}

	/**
	 * 构造一个含数据的数据表。(第一个字段必须为主键)
	 * 
	 * @param (String)str 提取数据的语句
	 * @param (String)name 数据表的名字
	 * @see : str: 'select A,B,C from .. where ...' KEY: 'A'
	 * 
	 */
	public final void create(String opername, String dbname, String str,
			HttpServletRequest request, int innum) {

		// 置主结果集
		my_session = request.getSession(true);
		initsession(dbname);
		if (my_session.getAttribute(s_pageend) == null) {
			if (innum < 0) {
				my_priv = new DataSimpDto(opername, str, 0);
			} else {
				my_priv = new DataSimpDto(opername, str, innum);
			}
			my_session.setAttribute(s_vecname, my_priv);

			// 置Hashtable
			my_prih = new Hashtable();
			my_psec = new Hashtable();
			convertVec();
			my_session.setAttribute(s_hmpfirt, my_prih);
			my_session.setAttribute(s_hmpsecd, my_psec);
			initvalue(dbname, request);
		}

	}

	public final void create(String dbname, String str,
			HttpServletRequest request, int innum) {

		// 置主结果集
		my_session = request.getSession(true);
		initsession(dbname);
		if (my_session.getAttribute(s_pageend) == null) {
			if (innum < 0) {
				my_priv = new DataSimpDto(str, 0);
			} else {
				my_priv = new DataSimpDto(str, innum);
			}
			my_session.setAttribute(s_vecname, my_priv);

			// 置Hashtable
			my_prih = new Hashtable();
			my_psec = new Hashtable();
			convertVec();
			my_session.setAttribute(s_hmpfirt, my_prih);
			my_session.setAttribute(s_hmpsecd, my_psec);
			initvalue(dbname, request);
		}

	}

	public final void create(String dbname, String str,
			HttpServletRequest request) {
		create(dbname, str, request, 0);
	}

	public final void create(String opername, String dbname, String str,
			HttpServletRequest request) {
		create(opername, dbname, str, request, 0);
	}

	/**
	 * 判断数据表是否为空。
	 * 
	 * @param (String)name 数据表的名字
	 * @return (boolean) true --空 ,false －非空
	 * 
	 */
	public final boolean isempty(String dbname, HttpServletRequest request) {
		if (!checkprivsession(dbname, request))
			return true;

		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) >= 1)
			return false;
		return true;
	}

	/**
	 * 得到数据表的总记录数。
	 * 
	 * @param (String)name 数据表的名字
	 * @return (int) recordnumber 总记录数
	 * 
	 */
	public final int getrow(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		return ((Integer) my_session.getAttribute(s_totreco)).intValue();
	}

	/**
	 * 得到数据表的总字段数。
	 * 
	 * @param (String)name 数据表的名字
	 * @return (int) fieldnumber 总字段数
	 * 
	 */
	public final int getfield(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		return ((Integer) my_session.getAttribute(s_totfiel)).intValue();
	}

	/**
	 * 得到数据表现在的记录号。
	 * 
	 * @param (String)name 数据表的名字
	 * @return (int) recordno 现在的记录号
	 * 
	 */
	public final int record(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 1)
			return 0;
		return ((Integer) my_session.getAttribute(s_nowreco)).intValue();
	}

	/**
	 * 移动数据表现在的记录。
	 * 
	 * @param (String)name 数据表的名字
	 * @param (int) movenumber 需移动的记录数 负值为上移
	 */
	public final void skip(String dbname, int movenumber,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 1)
			return;
		if (my_session.getAttribute(s_nowreco) == null)
			return;
		if (my_session.getAttribute(s_totreco) == null)
			return;

		int trec = ((Integer) my_session.getAttribute(s_totreco)).intValue(); // 总记录
		int ttrec = ((Integer) my_session.getAttribute(s_nowreco)).intValue(); // 当前记录

		if ((getrow(dbname, request) + movenumber) < 1)
			ttrec = 1;
		else {
			if (getrow(dbname, request) < movenumber)
				ttrec = trec;
			else
				ttrec = ttrec + movenumber;
		}
		int tfie = ((Integer) my_session.getAttribute(s_totfiel)).intValue(); // 总字段数
		int ttfie = 3 + tfie + ttrec * tfie;
		my_session.setAttribute(s_reconum, new Integer(ttfie));
		my_session.setAttribute(s_nowreco, new Integer(ttrec));

	}

	/**
	 * 移动数据表到第一条记录。
	 * 
	 * @param (String)name 数据表的名字
	 */
	public final void gofirst(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 1)
			return;

		int tfie = ((Integer) my_session.getAttribute(s_totfiel)).intValue(); // 总字段数
		my_session.setAttribute(s_reconum, new Integer(3 + tfie));
		my_session.setAttribute(s_nowreco, new Integer(1));
	}

	/**
	 * 移动数据表到最后一条记录。
	 * 
	 * @param (String)name 数据表的名字
	 */
	public final void golast(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 1)
			return;
		int tfie = ((Integer) my_session.getAttribute(s_totfiel)).intValue(); // 总字段数
		int trec = ((Integer) my_session.getAttribute(s_totreco)).intValue(); // 总记录
		my_session.setAttribute(s_reconum, new Integer(3 + tfie + tfie * trec));
		my_session.setAttribute(s_nowreco, new Integer(trec));
	}

	/**
	 * 查找某个主键值的记录号
	 * 
	 * @param (String)name 数据表的名字
	 * @param (String)keyvalue 主键值
	 * @return (int) 记录号 没找到 返回 0 , 指针不动
	 */
	public final int find(String dbname, String keyvalue,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 1)
			return 0;

		Hashtable my_psec = (Hashtable) my_session.getAttribute(s_hmpsecd);
		if (!my_psec.containsKey(keyvalue))
			return 0;
		int t_len = my_psec.get(keyvalue).toString().length();
		return Integer.parseInt(my_psec.get(keyvalue).toString()
				.substring(1, t_len));
	}

	/**
	 * 得到某个记录号的各字段的值。
	 * 
	 * @param (String)name 数据表的名字
	 * @param (String)fieldname 字段名//字段位置
	 * @param (int)recordnumber 记录号
	 * @return (String) 字段的值 如果为 null 返回 ""
	 * 
	 */
	public final String getvalue(String dbname, String fieldname,
			int recordnumber, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 1)
			return "";

		DataSimpDto tmpdto = (DataSimpDto) my_session.getAttribute(s_vecname);

		String temp = tmpdto.getDataValue(fieldname, recordnumber);
		return temp;
	}

	public final String getvalue(String dbname, int fieldnum, int recordnumber,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 1)
			return "";

		DataSimpDto tmpdto = (DataSimpDto) my_session.getAttribute(s_vecname);

		String temp = tmpdto.getDataValue(fieldnum, recordnumber);
		return temp;

	}

	/**
	 * 将某个范围的记录作删除标记。
	 * 
	 * @param (String)name 数据表的名字
	 * @param (int) firstnum 起始记录号
	 * @param (int) lastnum 截止记录号
	 * 
	 */
	public final void delete(String dbname, int firstnum, int lastnum,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 1)
			return;

		if ((firstnum < 0) || (firstnum > lastnum))
			return;
		int totrec = gettotreco(dbname, request);
		if (lastnum > totrec)
			return;

		Hashtable my_prih = (Hashtable) my_session.getAttribute(s_hmpfirt);
		Hashtable my_psec = (Hashtable) my_session.getAttribute(s_hmpsecd);
		for (int ttu = firstnum; ttu < lastnum; ttu++) {
			if (my_prih.containsKey(String.valueOf(ttu))) {
				String tt = my_prih.get(String.valueOf(ttu)).toString();
				if (!tt.startsWith("*")) {
					my_prih.put(String.valueOf(ttu), "*" + tt);
					my_psec.put(tt, "*" + String.valueOf(ttu));
				}
			}
		}
		my_session.setAttribute(s_hmpfirt, my_prih);
		my_session.setAttribute(s_hmpsecd, my_psec);
	}

	/**
	 * 将某个主键值作删除标记。
	 * 
	 * @param (String) name 数据表的名字
	 * @param (String) keyvalue 主键值
	 * 
	 */
	public final void delete(String dbname, String keyvalue,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 1)
			return;

		Hashtable my_prih = (Hashtable) my_session.getAttribute(s_hmpfirt);
		Hashtable my_psec = (Hashtable) my_session.getAttribute(s_hmpsecd);

		if (!my_psec.containsKey(keyvalue)) {
			return;
		}
		String tt = my_psec.get(keyvalue).toString().trim();

		if (tt.startsWith("*"))
			return;

		my_psec.put(keyvalue, "*" + tt);
		my_prih.put(tt, "*" + keyvalue);

		my_session.setAttribute(s_hmpfirt, my_prih);
		my_session.setAttribute(s_hmpsecd, my_psec);
	}

	/**
	 * 将某个记录范围作了删除标记 记录恢复。
	 * 
	 * @param (String)name 数据表的名字
	 * @param (int) firstnum 起始记录号
	 * @param (int) lastnum 截止记录号
	 * 
	 */
	public final void undelete(String dbname, int firstnum, int lastnum,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 1)
			return;

		if ((firstnum < 0) || (firstnum > lastnum))
			return;
		int totrec = gettotreco(dbname, request);
		if (lastnum > totrec)
			return;
		Hashtable my_prih = (Hashtable) my_session.getAttribute(s_hmpfirt);
		Hashtable my_psec = (Hashtable) my_session.getAttribute(s_hmpsecd);
		for (int ttint = firstnum; ttint < lastnum; ttint++) {
			if (my_prih.containsKey(String.valueOf(ttint))) {
				String tt = my_prih.get(String.valueOf(ttint)).toString();
				if (tt.startsWith("*")) {
					my_prih.put(String.valueOf(ttint), " " + tt.substring(1));
					my_psec.put(tt.substring(1), " " + String.valueOf(ttint));
				}
			}
		}
		my_session.setAttribute(s_hmpfirt, my_prih);
		my_session.setAttribute(s_hmpsecd, my_psec);
	}

	/**
	 * 将某个作了删除标记主键值恢复。
	 * 
	 * @param (String) name 数据表的名字
	 * @param (String) keyvalue 主键值
	 * 
	 */
	public final void undelete(String dbname, String keyvalue,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return;
		Hashtable my_prih = (Hashtable) my_session.getAttribute(s_hmpfirt);
		Hashtable my_psec = (Hashtable) my_session.getAttribute(s_hmpsecd);

		if (!my_psec.containsKey(keyvalue))
			return;
		String tt = my_psec.get(keyvalue).toString().trim();
		if (tt.startsWith("*")) {
			my_prih.put(keyvalue, " " + tt.substring(1));
			my_psec.put(tt.substring(1).trim(), " " + keyvalue);
		}
		my_session.setAttribute(s_hmpfirt, my_prih);
		my_session.setAttribute(s_hmpsecd, my_psec);
	}

	/**
	 * 设置 某一记录号 的某个字段 的值(不能为主键)。
	 * 
	 * @param (String) name 数据表的名字
	 * @param (String) fieldname 字段名//字段顺序号
	 * @param (int) recordno 记录号
	 * @param (String) newvalue 值
	 * 
	 */
	public final void replvalue(String dbname, String fieldname, int recordno,
			String newvalue, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return;

		DataSimpDto vec = (DataSimpDto) my_session.getAttribute(s_vecname);
		vec.setDataValue(fieldname, recordno, newvalue);
		my_session.setAttribute(s_vecname, vec);
		vec = null;
	}

	public final void replvalue(String dbname, int fieldnum, int recordno,
			String newvalue, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return;

		DataSimpDto vec = (DataSimpDto) my_session.getAttribute(s_vecname);
		vec.setDataValue(fieldnum, recordno, newvalue);
		my_session.setAttribute(s_vecname, vec);
		vec = null;
	}

	/**
	 * 将所有作了删除标记/未作标记 的记录置入HASHTABLE。
	 * 
	 * @param (int) sign 方式 0---作了删除标记的 1---未作删除标记的 2--全部
	 * @return (Hashtable) 返回结果集Hashtable
	 * 
	 */
	public Hashtable makehash(String dbname, int sign,
			HttpServletRequest request) {
		Hashtable newhash = new Hashtable();
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 1)
			return null;

		my_prih = (Hashtable) my_session.getAttribute(s_hmpfirt);
		for (int i = 0; i < gettotreco(dbname, request); i++) {
			String nowvalue = my_prih.get(String.valueOf(i)).toString().trim();
			if (nowvalue.startsWith("*") && sign != 1)
				newhash.put(nowvalue.substring(1), "");
			if (!nowvalue.startsWith("*") && sign != 0)
				newhash.put(nowvalue, "");
		}
		return newhash;
	}

	/**
	 * 判断某一记录表 的某个记录是否作了删除标记。
	 * 
	 * @param (String)name 数据表的名字
	 * @param (int)recordno 记录号 0--当前记录号
	 * @return (boolean) true --作了删除标记 false --未作
	 * 
	 */
	public boolean isdeleteno(String dbname, int recordno,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);

		if (getrow(dbname, request) < 0)
			return false;

		if (recordno < 1) {
			recordno = Integer.parseInt(my_session.getAttribute(s_nowreco)
					.toString());
		}

		my_prih = (Hashtable) my_session.getAttribute(s_hmpfirt);
		String nowvalue = (String) my_prih.get(String.valueOf(recordno));

		if (nowvalue.startsWith("*"))
			return true;
		return false;
	}

	/**
	 * 得到作了删除标记的某一范围 记录的数量。
	 * 
	 * @param (String)name 数据表的名字
	 * @param (int) startno 起始记录号
	 * @param (int) endno 截至记录号
	 * @return (int) 记录数量
	 * 
	 */
	public int deletecountno(String dbname, int startno, int endno,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return 0;

		if (startno < 0)
			return 0;
		if (startno > endno)
			return 0;
		int deletenum = 0;
		my_prih = (Hashtable) my_session.getAttribute(s_hmpfirt);
		for (int qq = startno; qq <= endno; qq++) {
			String tt = my_prih.get(String.valueOf(qq)).toString();
			if (tt.startsWith("*"))
				deletenum++;
		}
		return deletenum;
	}

	/**
	 * 判断某一记录表 的主键是否含有指定的值。
	 * 
	 * @param (String)name 数据表的名字
	 * @param (String)value 指定的值
	 * @param (int) recordnum 指定记录号 0--所有记录
	 * @return (boolean) true --含 false --不含
	 * 
	 */
	public final boolean isvalue(String dbname, String value, int recordnum,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return false;

		my_psec = (Hashtable) my_session.getAttribute(s_hmpsecd);
		my_prih = (Hashtable) my_session.getAttribute(s_hmpfirt);
		if (recordnum < 0) {
			if (my_psec.containsKey(value))
				return true;
		}
		String tt = my_prih.get(String.valueOf(recordnum)).toString();
		if (tt.substring(1, tt.length()).equals(value))
			return true;
		return false;
	}

	/**
	 * 返回某一记录表 的主键含有指定的值的记录号。
	 * 
	 * @param (String)name 数据表的名字
	 * @param (String)value 指定的值
	 * @return (int) 返回的记录号 0--没有找到含有值的主键
	 * 
	 */
	public final int contvalueno(String dbname, String value,
			HttpServletRequest request) {

		if (getrow(dbname, request) < 1)
			return 0;

		Hashtable hashNew = gethmpfirt(dbname, request);

		for (int nNowRec = 0; nNowRec < hashNew.size(); nNowRec++) {
			String tt = hashNew.get(String.valueOf(nNowRec)).toString();
			if (tt.substring(1).equals(value))
				return nNowRec;
		}
		return 0;
	}

	/**
	 * 得到某一页起始记录号。
	 * 
	 * @param (String)name 数据表的名字
	 * @param (int) pageno 页号
	 * @return (int) 起始记录号
	 * 
	 */
	public int pagestartno(String dbname, int pageno, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return 0;

		int totrec = gettotreco(dbname, request);
		int totpage = gettotpage(dbname, request);
		int pagsize = getpagsize(dbname, request);

		if (pageno >= totpage)
			return pagsize * (totpage - 1);

		return pagsize * (pageno - 1);
	}

	/**
	 * 得到某一页截止记录号。
	 * 
	 * @param (String)name 数据表的名字
	 * @param (int) pageno 页号
	 * @return (int) 截止记录号
	 * 
	 */
	public int pageendno(String dbname, int pageno, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 1)
			return 0;

		int totrec = gettotreco(dbname, request);
		int totpage = gettotpage(dbname, request);
		int pagsize = getpagsize(dbname, request);

		if (pageno >= totpage)
			return totrec;
		return pagsize * pageno;
	}

	/**
	 * 得到当前已添加的记录值。
	 * 
	 * @param (String)name 数据表的名字
	 * 
	 */
	public final int getaddreco(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return 0;
		return Integer.parseInt(my_session.getAttribute(s_addreco).toString());
	}

	/**
	 * 设置当前已添加的记录值。
	 * 
	 * @param (String)name 数据表的名字
	 * @param (int) n_number 当前已添加的记录值
	 * 
	 */
	public final void setaddreco(String dbname, int n_number,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return;
		my_session.setAttribute(s_addreco, new Integer(n_number));
	}

	/**
	 * 设置当前页的起始记录值。
	 * 
	 * @param (String)name 数据表的名字
	 * @param (int) n_number 当前页的起始记录值
	 * 
	 */
	public final void setpagefrc(String dbname, int n_number,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return;
		my_session.setAttribute(s_pagefrc, new Integer(n_number));
	}

	/**
	 * 得到当前页的起始记录值。
	 * 
	 * @param (String)name 数据表的名字
	 * 
	 */
	public final int getpagefrc(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		my_session.setMaxInactiveInterval(-1);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return 0;
		return Integer.parseInt(my_session.getAttribute(s_pagefrc).toString());
	}

	/**
	 * 设置当前页的截止记录值。
	 * 
	 * @param (String)name 数据表的名字
	 * @param (int) n_number 当前页的截止记录值
	 * 
	 */
	public final void setpageerc(String dbname, int n_number,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return;
		my_session.setAttribute(s_pageerc, new Integer(n_number));
	}

	/**
	 * 得到当前页的截止记录值。
	 * 
	 * @param (String)name 数据表的名字
	 * 
	 */
	public final int getpageerc(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return 0;
		return Integer.parseInt(my_session.getAttribute(s_pageerc).toString());
	}

	/**
	 * 设置当前页的起始偏移量。
	 * 
	 * @param (String)name 数据表的名字
	 * @param (int) n_number 当前页的起始偏移量
	 * 
	 */
	public final void setpagefir(String dbname, int n_number,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return;
		my_session.setAttribute(s_pagefir, new Integer(n_number));
	}

	/**
	 * 得到当前页的起始偏移量。
	 * 
	 * @param (String)name 数据表的名字
	 * @return (int) 当前页的起始偏移量
	 */
	public final int getpagefir(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return 0;
		return Integer.parseInt(my_session.getAttribute(s_pagefir).toString());
	}

	/**
	 * 设置当前页的截止偏移量。
	 * 
	 * @param (String)name 数据表的名字
	 * @param (int) n_number 当前页的截止偏移量
	 * 
	 */
	public final void setpageend(String dbname, int n_number,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return;
		my_session.setAttribute(s_pageend, new Integer(n_number));
	}

	/**
	 * 得到当前页的截止偏移量。
	 * 
	 * @param (String)name 数据表的名字
	 * 
	 */
	public final int getpageend(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		my_session.setMaxInactiveInterval(-1);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return 0;
		return Integer.parseInt(my_session.getAttribute(s_pageend).toString());
	}

	/**
	 * 得到当前页的页号。
	 * 
	 * @param (String)name 数据表的名字
	 * @return (int) 当前页的页号
	 * 
	 */
	public final int getnowpage(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return 0;
		if (my_session.getAttribute(s_nowpage) == null)
			return 0;
		return Integer.parseInt(my_session.getAttribute(s_nowpage).toString());
	}

	/**
	 * 设置每页记录数。
	 * 
	 * @param (String) name 数据表的名字
	 * @param (int) n_number 每页的记录数量
	 * 
	 */
	public final void setpagsize(String dbname, int n_number,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (my_session.getAttribute(s_totreco) == null)
			return;
		if (getrow(dbname, request) < 0)
			return;

		if (n_number < 0)
			return;
		my_session.setAttribute(s_pagsize, new Integer(n_number));
		int totreco = Integer.parseInt(my_session.getAttribute(s_totreco)
				.toString());
		int totpage = totreco / n_number;
		if ((totpage * n_number) != totreco)
			totpage++;
		my_session.setAttribute(s_totpage, new Integer(totpage));
	}

	/**
	 * 得到每页记录数。
	 * 
	 * @param (String)name 数据表的名字
	 * @return (int)每页记录数
	 */
	public final int getpagsize(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return 0;
		if (my_session.getAttribute(s_pagsize) == null)
			return 0;
		return Integer.parseInt(my_session.getAttribute(s_pagsize).toString());
	}

	/**
	 * 设置当前记录值的偏移量。
	 * 
	 * @param (String)name 数据表的名字
	 * @param (int) n_number 当前记录值的偏移量
	 * 
	 */
	public final void setreconum(String dbname, int n_number,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return;
		my_session.setAttribute(s_reconum, new Integer(n_number));
	}

	/**
	 * 得到当前记录值的偏移量。
	 * 
	 * @param (String)name 数据表的名字
	 * 
	 */
	public final int getreconum(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		my_session.setMaxInactiveInterval(-1);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return 0;
		if (my_session.getAttribute(s_reconum) == null)
			return 0;
		return Integer.parseInt(my_session.getAttribute(s_reconum).toString());
	}

	/**
	 * 设置当前记录值。
	 * 
	 * @param (String)name 数据表的名字
	 * @param (int) n_number 当前记录值
	 * 
	 */
	public final void setnowreco(String dbname, int n_number,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return;
		my_session.setAttribute(s_nowreco, new Integer(n_number));
	}

	/**
	 * 得到当前记录值。
	 * 
	 * @param (String)name 数据表的名字
	 * 
	 */
	public final int getnowreco(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return 0;
		if (my_session.getAttribute(s_nowreco) == null)
			return 0;
		return Integer.parseInt(my_session.getAttribute(s_nowreco).toString());
	}

	/**
	 * 设置结果集总字段数。
	 * 
	 * @param (String)name 数据表的名字
	 * @param (int) n_number 结果集总字段数
	 * 
	 */
	public final void settotfiel(String dbname, int n_number,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return;
		my_session.setAttribute(s_totfiel, new Integer(n_number));
	}

	/**
	 * 得到结果集总字段数。
	 * 
	 * @ param (String)name 数据表的名字
	 * 
	 */
	public final int gettotfiel(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return 0;
		if (my_session.getAttribute(s_totfiel) == null)
			return 0;
		return Integer.parseInt(my_session.getAttribute(s_totfiel).toString());
	}

	/**
	 * 设置结果集总页数。
	 * 
	 * @param (String)name 数据表的名字
	 * @param (int) n_number 结果集总页数
	 * 
	 */
	public final void settotpage(String dbname, int n_number,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return;
		my_session.setAttribute(s_totpage, new Integer(n_number));
	}

	/**
	 * 得到结果集总页数。
	 * 
	 * @param (String)name 数据表的名字
	 * 
	 */
	public final int gettotpage(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return 0;
		if (my_session.getAttribute(s_totpage) == null)
			return 0;
		return Integer.parseInt(my_session.getAttribute(s_totpage).toString());
	}

	/**
	 * 设置结果集总记录数。
	 * 
	 * @param (String)name 数据表的名字
	 * @param (int) n_number 结果集总记录数
	 * 
	 */
	public final void settotreco(String dbname, int n_number,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return;
		my_session.setAttribute(s_totreco, new Integer(n_number));
	}

	/**
	 * 得到结果集总记录数。
	 * 
	 * @param (String)name 数据表的名字
	 * 
	 */
	public final int gettotreco(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return 0;
		if (my_session.getAttribute(s_totreco) == null)
			return 0;
		return Integer.parseInt(my_session.getAttribute(s_totreco).toString());
	}

	/**
	 * 设置结果集。
	 * 
	 * @param (ArrayList)vec ArrayList结果集
	 * @param (HttpServletRequest request)
	 * 
	 */
	public final void setvecname(String dbname, DataSimpDto vec,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return;
		my_session.setAttribute(s_vecname, (DataSimpDto) vec);
	}

	/**
	 * 得到结果集。
	 * 
	 * @param (HttpServletRequest request)
	 * @return ArrayList 结果集 ArrayList
	 * 
	 */
	public final DataSimpDto getvecname(String dbname,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (my_session.getAttribute(s_vecname) == null)
			return null;
		return (DataSimpDto) my_session.getAttribute(s_vecname);
	}

	/**
	 * 设置第一个HASHTABLE。
	 * 
	 * @param (String)name 数据表的名字
	 * @param (Hashtable)hsb 第一个HASHTABLE
	 * 
	 */
	public final void sethmpfirt(String dbname, Hashtable hsb,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 1)
			return;

		my_session.setAttribute(s_hmpfirt, (Hashtable) hsb);
	}

	/**
	 * 得到第一个HASHTABLE。
	 * 
	 * @param (String)name 数据表的名字
	 * 
	 */
	public final Hashtable gethmpfirt(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return null;
		if (my_session.getAttribute(s_hmpfirt) == null)
			return null;
		return (Hashtable) my_session.getAttribute(s_hmpfirt);
	}

	/**
	 * 设置第二个HASHTABLE。
	 * 
	 * @param (String)name 数据表的名字
	 * @param (Hashtable)hsb 第二个HASHTABLE
	 * 
	 */
	public final void sethmpsecd(String dbname, Hashtable hsb,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 1)
			return;
		my_session.setAttribute(s_hmpsecd, (Hashtable) hsb);
	}

	/**
	 * 得到第二个HASHTABLE。
	 * 
	 * @param (String)name 数据表的名字
	 * 
	 */
	public final Hashtable gethmpsecd(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return null;
		if (my_session.getAttribute(s_hmpsecd) == null)
			return null;
		return (Hashtable) my_session.getAttribute(s_hmpsecd);
	}

	/**
	 * 得到当前行的各字段的值。
	 * 
	 * @param (String)name 数据表的名字
	 * @param (String)fieldname 字段名/字段位置
	 * @return (String) 字段的值 如果为 null 返回 ""
	 * 
	 */
	public String getvalue(String dbname, String fieldname,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 1)
			return "";
		if (my_session.getAttribute(s_hmpsecd) == null)
			return "";

		return getvalue(dbname, fieldname, record(dbname, request), request);
	}

	public String getvalue(String dbname, int fieldnum,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 1)
			return "";
		if (my_session.getAttribute(s_hmpsecd) == null)
			return "";
		return getvalue(dbname, fieldnum, record(dbname, request), request);
	}

	/**
	 * 得到作了删除标记的所有记录的数量。
	 * 
	 * @param (String)name 数据表的名字
	 * @return (int) 记录数量
	 * 
	 */
	public int deletecount(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return 0;
		if (my_session.getAttribute(s_hmpsecd) == null)
			return 0;
		return deletecountno(dbname, 0, gettotreco(dbname, request), request);
	}

	/**
	 * 判断所有记录是否均作了删除标记。
	 * 
	 * @param (String)name 数据表的名字
	 * @return (boolean) true -- false --未作
	 * 
	 */
	public final boolean ifhasdel(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		for (int i = 0; i < this.gettotreco(dbname, request); i++) {
			if (!isdeleteno(dbname, i, request))
				return false;
		}
		return true;
	}

	/**
	 * 判断当前记录是否作了删除标记。
	 * 
	 * @param (String)name 数据表的名字
	 * @return (boolean) true --作了删除标记 false --未作
	 * 
	 */
	public final boolean isdelete(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return false;
		if (my_session.getAttribute(s_hmpsecd) == null)
			return false;
		return isdeleteno(dbname, 0, request);
	}

	/**
	 * 将所有作了删除标记的记录恢复。
	 * 
	 * @param (String) name 数据表的名字
	 * 
	 */
	public void undeleteall(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return;
		if (my_session.getAttribute(s_hmpsecd) == null)
			return;

		undelete(dbname, 0, gettotreco(dbname, request), request);
	}

	/**
	 * 将某页内所有作了删除标记的记录恢复。
	 * 
	 * @param (String) pagenum 指定页
	 * 
	 */
	public void undeleteinpage(String dbname, int pagenum,
			HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 0)
			return;
		if (my_session.getAttribute(s_hmpsecd) == null)
			return;

		undelete(dbname, pagestartno(dbname, pagenum, request),
				pageendno(dbname, pagenum, request), request);
	}

	/**
	 * 判断数据表是否存在。
	 * 
	 * @return true--存在 false--不存在
	 * 
	 */
	public boolean isexist(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (my_session.getAttribute(s_totreco) == null)
			return false;

		return true;
	}

	/**
	 * 释放数据表SESSION。
	 * 
	 */
	public void releasesession(String dbname, HttpServletRequest request) {

		my_session = request.getSession(true);
		initsession(dbname);
		my_session.removeAttribute(s_pageend);
		my_session.removeAttribute(s_vecname);
		my_session.removeAttribute(s_hmpfirt);
		my_session.removeAttribute(s_hmpsecd);
		my_session.removeAttribute(s_totreco);

		my_session.removeAttribute(s_totpage);
		my_session.removeAttribute(s_totfiel);
		my_session.removeAttribute(s_nowreco);
		my_session.removeAttribute(s_reconum);
		my_session.removeAttribute(s_pagsize);

		my_session.removeAttribute(s_nowpage);
		my_session.removeAttribute(s_pagefir);
		my_session.removeAttribute(s_pageend);
		my_session.removeAttribute(s_pagefrc);
		my_session.removeAttribute(s_pageerc);

		my_session.removeAttribute(s_filtval);
		my_session.removeAttribute(s_filtkey);
		my_session.removeAttribute(s_vecfilt);

		System.gc();
	}

	private void setvalue(String dbname, String fieldname, int fieldloc,
			int recordnum, String newvalue, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 1)
			return;

		DataSimpDto newvec = getvecname(dbname, request);

		if (fieldname.equals(""))
			newvec.setDataValue(fieldloc, recordnum, newvalue);
		else
			newvec.setDataValue(fieldname, recordnum, newvalue);

		setvecname(dbname, newvec, request);
		newvec = null;
	}

	private boolean checkprivsession(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		my_session.setMaxInactiveInterval(-1);
		initsession(dbname);

		if (my_session.getAttribute(s_vecname) == null)
			return false;
		if (my_session.getAttribute(s_hmpfirt) == null)
			return false;
		if (my_session.getAttribute(s_hmpsecd) == null)
			return false;
		if (my_session.getAttribute(s_totreco) == null)
			return false;
		if (my_session.getAttribute(s_totpage) == null)
			return false;

		if (my_session.getAttribute(s_totfiel) == null)
			return false;
		if (my_session.getAttribute(s_nowreco) == null)
			return false;
		if (my_session.getAttribute(s_reconum) == null)
			return false;
		if (my_session.getAttribute(s_pagsize) == null)
			return false;

		if (my_session.getAttribute(s_nowpage) == null)
			return false;
		if (my_session.getAttribute(s_pagefir) == null)
			return false;
		if (my_session.getAttribute(s_pageend) == null)
			return false;
		if (my_session.getAttribute(s_pagefrc) == null)
			return false;
		if (my_session.getAttribute(s_pageerc) == null)
			return false;
		return true;
	}

	/**
	 * 设置某一记录的各字段的值。(不能为主键)
	 * 
	 * @param (String)fieldname/(int)fieldloc 字段名/字段位置
	 * @param (int) recordnum 记录号
	 * @param (String) 设置的新值
	 * 
	 */
	public void setvalue(String dbname, String fieldname, int recordnum,
			String newvalue, HttpServletRequest request) {
		setvalue(dbname, fieldname, 0, recordnum, newvalue, request);
	}

	public void setvalue(String dbname, int fieldnum, int recordnum,
			String newvalue, HttpServletRequest request) {
		setvalue(dbname, "", fieldnum, recordnum, newvalue, request);
	}

	/**
	 * 设置当前记录的各字段的值。(不能为主键)
	 * 
	 * @param (String)fieldname/(int)fieldloc 字段名/字段位置
	 * @param (String)newvalue 设置的新值
	 * 
	 */
	public void setvaluenow(String dbname, String fieldname, String newvalue,
			HttpServletRequest request) {
		setvalue(dbname, fieldname, getrow(dbname, request), newvalue, request);
	}

	public void setvaluenow(String dbname, int fieldloc, String newvalue,
			HttpServletRequest request) {
		setvalue(dbname, fieldloc, getrow(dbname, request), newvalue, request);
	}

	/**
	 * 将指定字段的值，去掉小数位之后的零值
	 * 
	 * @param (String)fieldname/(int)fieldloc 字段名/字段位置
	 * 
	 */
	public void removedotvalue(String dbname, String fieldname,
			HttpServletRequest request) {
		for (int i = 1; i <= gettotreco(dbname, request); i++) {
			String newvalue = getvalue(dbname, fieldname, i, request);
			if (newvalue.indexOf(".") > 0) {
				for (int j = 0; j < newvalue.length(); j++) {
					newvalue = removedot(newvalue);
				}
			}
			setvalue(dbname, fieldname, i, newvalue, request);
		}
	}

	public void removedotvalue(String dbname, int fieldloc,
			HttpServletRequest request) {
		for (int i = 1; i <= gettotreco(dbname, request); i++) {
			String newvalue = getvalue(dbname, fieldloc, i, request);
			if (newvalue.indexOf(".") > 0) {
				for (int j = 0; j < newvalue.length(); j++) {
					newvalue = removedot(newvalue);
				}
			}
			setvalue(dbname, fieldloc, i, newvalue, request);
		}
	}

	private String removedot(String oldvalue) {
		if (oldvalue.substring(oldvalue.length() - 1).equals("."))
			return oldvalue.substring(0, oldvalue.length() - 1);
		if (oldvalue.indexOf(".") > 0) {
			if (oldvalue.substring(oldvalue.length() - 1).equals("0"))
				return oldvalue.substring(0, oldvalue.length() - 1);
		}
		return oldvalue;
	}

	// ------------------------------------------------------------------------------------------------------------
	// 以下进行条件过滤记录处理
	// ------------------------------------------------------------------------------------------------------------
	/**
	 * 设置过滤 KEY 值。
	 * 
	 */
	public final void setFiltKey(String dbname, String keyvalue,
			HttpServletRequest request) {

		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 1)
			return;

		my_session.setAttribute(s_filtkey, keyvalue);

		return;
	}

	/**
	 * 得到某个结果集的过滤总数。
	 * 
	 */
	public final int getFtotrec(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 1)
			return 0;

		ArrayList newvec = (ArrayList) my_session.getAttribute(s_vecfilt);
		int temp = newvec.size();
		newvec = null;
		return temp;
	}

	/**
	 * 得到某个结果集过滤记录号的值。
	 * 
	 */
	public final String getFvalue(String dbname, String fieldname,
			int recordno, HttpServletRequest request) {

		if (recordno < 1)
			return "";

		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 1)
			return "";
		recordno--;
		ArrayList newvec = (ArrayList) my_session.getAttribute(s_vecfilt);

		String newrec = (String) newvec.get(recordno);
		int nrec = Integer.valueOf(newrec).intValue();
		newrec = null;
		return getvalue(dbname, fieldname, nrec, request);
	}

	public final String getFvalue(String dbname, int fieldloc, int recordno,
			HttpServletRequest request) {

		if (recordno < 1)
			return "";

		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 1)
			return "";
		recordno--;
		ArrayList newvec = (ArrayList) my_session.getAttribute(s_vecfilt);

		String newrec = (String) newvec.get(recordno);
		int nrec = Integer.valueOf(newrec).intValue();
		newvec = null;
		return getvalue(dbname, fieldloc, nrec, request);
	}

	/**
	 * 对某个结果集进行过滤。
	 * 
	 * @param (String) keyvalue 过滤值
	 * 
	 */
	public final void filtrecord(String dbname, String keyvalue,
			HttpServletRequest request) {

		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 1)
			return;

		String nowfiltkey = (String) my_session.getAttribute(s_filtkey);

		ArrayList newvec = new ArrayList();
		for (int i = 1; i <= this.gettotreco(dbname, request); i++) {
			if (nowfiltkey.equals("")) {
				newvec.add(String.valueOf(i));
			} else {
				String nowvalue = getvalue(dbname, nowfiltkey, i, request);
				if (nowvalue.length() >= keyvalue.length()) {
					if (nowvalue.substring(0, keyvalue.length())
							.equalsIgnoreCase(keyvalue)) {
						newvec.add(String.valueOf(i));
					}
				}
			}
		}
		my_session.setAttribute(s_vecfilt, newvec);
		my_session.setAttribute(s_filtval, keyvalue);
		newvec = null;
		return;
	}

	/**
	 * 判断指定的记录是否已被过滤。
	 * 
	 * @param (int)recordno 记录号
	 * @return boolean true/false;
	 * 
	 */
	public boolean isfilt(String dbname, int recordno,
			HttpServletRequest request) {

		my_session = request.getSession(true);
		initsession(dbname);
		if (getrow(dbname, request) < 1)
			return false;

		String nowfiltkey = (String) my_session.getAttribute(s_filtkey);
		String nowfiltval = (String) my_session.getAttribute(s_filtval);

		if (nowfiltkey.equals(""))
			return false;
		if (nowfiltval.equals(""))
			return true;

		ArrayList newvec = (ArrayList) my_session.getAttribute(s_vecfilt);
		if (newvec.size() < 1)
			return false;

		for (int i = 0; i < newvec.size(); i++) {
			String nowrec = (String) newvec.get(i);
			String strrec = String.valueOf(recordno);
			if (nowrec.equals(strrec.trim()))
				return true;
		}
		newvec = null;
		return false;
	}

	/**
	 * 清空过滤键值
	 * 
	 */
	public void clearfilt(String dbname, HttpServletRequest request) {
		my_session = request.getSession(true);
		initsession(dbname);

		// 当前的数据过滤字段
		my_session.setAttribute(s_filtkey, "");
		// 当前的数据过滤值
		my_session.setAttribute(s_filtval, "");
		// 当前过滤值对应的顺序号
		my_session.setAttribute(s_vecfilt, new ArrayList());
	}

	public static int getSumPage(DataSimpDto vt, int onePageCount) {
		int row = vt.getTotRecord();
		if (onePageCount <= 0)
			return 0;
		if ((float) row / onePageCount > (int) row / onePageCount) {
			return (int) row / onePageCount + 1;
		} else {
			return (int) row / onePageCount;
		}
	}

	/**
	 * 释放公共结果集 (未用)
	 */
	public void relepubdatasource(HttpServletRequest request) {
	}

	/**
	 * 句柄，供调用
	 */
	public static VisuTable getInst() {
		vecpool = new VisuTable();

		return vecpool;
	}
}
